﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Interface_Design
{
    public partial class Form1 : Form
    {
        Point mouseOffset = new Point();
        private bool mouseDown = false;
        IniFile configINI;
        SettingsForm settingsForm = new SettingsForm();

        public Form1()
        {
            InitializeComponent();
            this.FormBorderStyle = FormBorderStyle.None;

            configINI = new IniFile(@"..\..\Configuration\interfaceConfig.ini");   
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.BackColor = Color.Aqua;
            backgroundPictureBox.BackColor = Color.Aqua;
            this.TransparencyKey = Color.Aqua;

            int x = Int32.Parse(configINI.IniReadValue("ControlPanel", "startX"));
            int y = Int32.Parse(configINI.IniReadValue("ControlPanel", "startY"));
            this.Location = new Point(x, y);

            AppDock appDock = new AppDock();
            appDock.Show();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            configINI.IniWriteValue("ControlPanel", "startX", this.Location.X.ToString());
            configINI.IniWriteValue("ControlPanel", "startY", this.Location.Y.ToString());
        }

        private void pictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                mouseOffset = new Point(-e.X - SystemInformation.FrameBorderSize.Width, -e.Y - SystemInformation.FrameBorderSize.Height);
                mouseDown = true;
            }
        }

        private void pictureBox_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
                mouseDown = false;
        }

        private void pictureBox_MouseMove(object sender, MouseEventArgs e)
        {
            if (mouseDown)
            {
                Point mousePosition = Control.MousePosition;
                mousePosition.Offset(mouseOffset.X, mouseOffset.Y);
                this.Location = mousePosition;
            }
        }

        private void pictureBox_Click(object sender, EventArgs e)
        {
            PictureBox pictureBox = (PictureBox)sender;

            if (pictureBox.Image.Tag == null || pictureBox.Image.Tag.ToString() == "ON")
            {
                pictureBox.Image = Image.FromFile(@"..\..\Images\off.png");
                pictureBox.Image.Tag = "OFF";
            }
            else if (pictureBox.Image.Tag.ToString() == "OFF")
            {
                pictureBox.Image = Image.FromFile(@"..\..\Images\on.png");
                pictureBox.Image.Tag = "ON";
            }
        }

        private void menuArrow_Click(object sender, EventArgs e)
        {
            if (settingsForm.Visible != true)
                settingsForm.Show();
        }
    }
}
